package com.hzjy.manage.controller;

import java.util.List;

import com.hzjy.api.beans.HzjyAdvertising;
import com.hzjy.api.service.impl.HzjyAdvertisingServiceImpl;
import com.hzjy.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hzjy.common.annotation.Log;
import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.enums.BusinessType;
import com.hzjy.common.core.page.TableDataInfo;

/**
 * 广告位Controller
 * 
 * @author hzjy
 * @date 2020-09-22
 */
@RestController
@RequestMapping("/manage/advertising")
public class AdvertisingController extends BaseController
{
    @Autowired
    private HzjyAdvertisingServiceImpl hzjyAdvertisingService;

    /**
     * 查询广告位列表
     */
    @PreAuthorize("@ss.hasPermi('manage:advertising:list')")
    @GetMapping("/list")
    public TableDataInfo list(HzjyAdvertising hzjyAdvertising)
    {
        startPage();
        List<HzjyAdvertising> list = hzjyAdvertisingService.selectAdvertisingList(hzjyAdvertising);
        return getDataTable(list);
    }

    /**
     * 导出广告位列表
     */
    @PreAuthorize("@ss.hasPermi('manage:advertising:export')")
    @Log(title = "广告位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HzjyAdvertising hzjyAdvertising)
    {
        List<HzjyAdvertising> list = hzjyAdvertisingService.selectHzjyAdvertisingList(hzjyAdvertising);
        ExcelUtil<HzjyAdvertising> util = new ExcelUtil<HzjyAdvertising>(HzjyAdvertising.class);
        return util.exportExcel(list, "advertising");
    }

    /**
     * 获取广告位详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:advertising:query')")
    @GetMapping(value = "/selectOne")
    public AjaxResult getInfo(Long id)
    {
        return AjaxResult.success(hzjyAdvertisingService.selectHzjyAdvertisingById(id));
    }

    /**
     * 新增广告位
     */
    @PreAuthorize("@ss.hasPermi('manage:advertising:add')")
    @Log(title = "广告位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody HzjyAdvertising hzjyAdvertising)
    {
        return toAjax(hzjyAdvertisingService.insertHzjyAdvertising(hzjyAdvertising));
    }

    /**
     * 修改广告位
     */
    @PreAuthorize("@ss.hasPermi('manage:advertising:edit')")
    @Log(title = "广告位", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody HzjyAdvertising hzjyAdvertising)
    {
        return toAjax(hzjyAdvertisingService.updateHzjyAdvertising(hzjyAdvertising));
    }

    /**
     * 批量删除广告位
     */
    @PreAuthorize("@ss.hasPermi('manage:advertising:remove')")
    @Log(title = "广告位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hzjyAdvertisingService.deleteHzjyAdvertisingByIds(ids));
    }

    /**
     * 删除广告位
     */
    @PreAuthorize("@ss.hasPermi('manage:advertising:delete')")
    @Log(title = "广告位", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody HzjyAdvertising hzjyAdvertising)
    {
        return toAjax(hzjyAdvertisingService.deleteHzjyAdvertisingById(hzjyAdvertising.getId()));
    }
}
